package file;

import java.io.*;

public class FileApplication {
    public static void main(String[] args) {
        writer();
    }

    public static void writer(){
        File file = new File("hello.txt");
        BufferedWriter bw = null;
        try {
            bw = new BufferedWriter(new FileWriter(file));
            bw.write("nuna salaheiyou");
            bw.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if(bw != null){
                try {
                    bw.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public static void read() {
        File file = new File("C:\\Users\\lenovo\\Desktop\\demo.txt");
        FileReader fr = null;
        try {
            fr = new FileReader(file);
            int tmp = fr.read();
            while (tmp != -1){
                System.out.print((char)tmp);
                tmp = fr.read();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }finally {
            if(fr != null){
                try {
                    fr.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

    }

}

